{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from downloaddata import DlStock\n",
    "import pandas as pd\n",
    "import os\n",
    "from tqdm import tqdm\n",
    "import shutil\n",
    "import time\n",
    "import random"
   ]
  },
  {
   "cell_type": "markdown",
   "source": [
    "## 下载浦发银行数据\n",
    "一个简单的案例说明"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "downloading...: 100%|██████████| 89/89 [00:03<00:00, 24.55it/s]\n"
     ]
    },
    {
     "data": {
      "text/plain": "           日期    开盘价    最高价    最低价    收盘价    涨跌额  涨跌幅(%)   成交量(手)  成交金额(万元)  \\\n0  1999-11-10  29.50  29.80  27.00  27.75  17.75  177.50  1740851    485910   \n1  1999-11-11  27.58  28.38  27.53  27.71  -0.04   -0.14   294035     82158   \n2  1999-11-12  27.86  28.30  27.77  28.05   0.34    1.23   150080     42159   \n3  1999-11-15  28.20  28.25  27.70  27.75  -0.30   -1.07   119211     33295   \n4  1999-11-16  27.88  27.97  26.48  26.55  -1.20   -4.32   232231     62891   \n\n   振幅(%)  换手率(%)  \n0  28.00   54.40  \n1   3.06    9.19  \n2   1.91    4.69  \n3   1.96    3.73  \n4   5.37    7.26  ",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>日期</th>\n      <th>开盘价</th>\n      <th>最高价</th>\n      <th>最低价</th>\n      <th>收盘价</th>\n      <th>涨跌额</th>\n      <th>涨跌幅(%)</th>\n      <th>成交量(手)</th>\n      <th>成交金额(万元)</th>\n      <th>振幅(%)</th>\n      <th>换手率(%)</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>1999-11-10</td>\n      <td>29.50</td>\n      <td>29.80</td>\n      <td>27.00</td>\n      <td>27.75</td>\n      <td>17.75</td>\n      <td>177.50</td>\n      <td>1740851</td>\n      <td>485910</td>\n      <td>28.00</td>\n      <td>54.40</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>1999-11-11</td>\n      <td>27.58</td>\n      <td>28.38</td>\n      <td>27.53</td>\n      <td>27.71</td>\n      <td>-0.04</td>\n      <td>-0.14</td>\n      <td>294035</td>\n      <td>82158</td>\n      <td>3.06</td>\n      <td>9.19</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>1999-11-12</td>\n      <td>27.86</td>\n      <td>28.30</td>\n      <td>27.77</td>\n      <td>28.05</td>\n      <td>0.34</td>\n      <td>1.23</td>\n      <td>150080</td>\n      <td>42159</td>\n      <td>1.91</td>\n      <td>4.69</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>1999-11-15</td>\n      <td>28.20</td>\n      <td>28.25</td>\n      <td>27.70</td>\n      <td>27.75</td>\n      <td>-0.30</td>\n      <td>-1.07</td>\n      <td>119211</td>\n      <td>33295</td>\n      <td>1.96</td>\n      <td>3.73</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>1999-11-16</td>\n      <td>27.88</td>\n      <td>27.97</td>\n      <td>26.48</td>\n      <td>26.55</td>\n      <td>-1.20</td>\n      <td>-4.32</td>\n      <td>232231</td>\n      <td>62891</td>\n      <td>5.37</td>\n      <td>7.26</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dlstock_object = DlStock(stock_id='600000', start_date='1999-11-10', end_date='2021-10-25')\n",
    "data1 = dlstock_object.run()\n",
    "data1.head()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "# 如何批量下载上海证券交易所的A股的所有数据\n",
    "## 方法1. 使用for循环下载数据"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [],
   "source": [
    "dir_name = \"股票下载文件夹\"\n",
    "if os.path.exists(dir_name):\n",
    "    shutil.rmtree(path=dir_name)\n",
    "    os.mkdir(path=dir_name)\n",
    "else:\n",
    "    os.mkdir(path=dir_name)\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "outputs": [
    {
     "data": {
      "text/plain": "     公司代码    公司简称      代码      简称          上市日期 Unnamed: 5\n0  600000    浦发银行  600000    浦发银行    1999-11-10           \n1  600004    白云机场  600004    白云机场    2003-04-28           \n2  600006    东风汽车  600006    东风汽车    1999-07-27           \n3  600007    中国国贸  600007    中国国贸    1999-03-12           \n4  600008    首创环保  600008    首创环保    2000-04-27           ",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>公司代码</th>\n      <th>公司简称</th>\n      <th>代码</th>\n      <th>简称</th>\n      <th>上市日期</th>\n      <th>Unnamed: 5</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>600000</td>\n      <td>浦发银行</td>\n      <td>600000</td>\n      <td>浦发银行</td>\n      <td>1999-11-10</td>\n      <td></td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>600004</td>\n      <td>白云机场</td>\n      <td>600004</td>\n      <td>白云机场</td>\n      <td>2003-04-28</td>\n      <td></td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>600006</td>\n      <td>东风汽车</td>\n      <td>600006</td>\n      <td>东风汽车</td>\n      <td>1999-07-27</td>\n      <td></td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>600007</td>\n      <td>中国国贸</td>\n      <td>600007</td>\n      <td>中国国贸</td>\n      <td>1999-03-12</td>\n      <td></td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>600008</td>\n      <td>首创环保</td>\n      <td>600008</td>\n      <td>首创环保</td>\n      <td>2000-04-27</td>\n      <td></td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sz_A_stock_data = pd.read_csv(\"上海证券交易所股票名单/主板A股.xls\",\n",
    "                              sep='\\t',\n",
    "                              encoding='gb2312')\n",
    "sz_A_stock_data.columns = [i.strip() for i in sz_A_stock_data.columns.tolist()]\n",
    "sz_A_stock_data.head()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "  0%|          | 0/1645 [00:00<?, ?it/s]\n",
      "downloading...:   0%|          | 0/89 [00:00<?, ?it/s]\u001B[A\n",
      "downloading...:  22%|██▏       | 20/89 [00:00<00:01, 67.35it/s]\u001B[A\n",
      "downloading...:  34%|███▎      | 30/89 [00:00<00:00, 59.43it/s]\u001B[A\n",
      "downloading...:  45%|████▍     | 40/89 [00:00<00:00, 54.63it/s]\u001B[A\n",
      "downloading...:  56%|█████▌    | 50/89 [00:00<00:00, 46.22it/s]\u001B[A\n",
      "downloading...:  67%|██████▋   | 60/89 [00:01<00:00, 49.29it/s]\u001B[A\n",
      "downloading...:  79%|███████▊  | 70/89 [00:01<00:00, 47.57it/s]\u001B[A\n",
      "downloading...: 100%|██████████| 89/89 [00:01<00:00, 55.13it/s]\u001B[A\n",
      "  0%|          | 1/1645 [00:02<57:42,  2.11s/it]\n",
      "downloading...:   0%|          | 0/75 [00:00<?, ?it/s]\u001B[A\n",
      "downloading...:  27%|██▋       | 20/75 [00:00<00:00, 80.11it/s]\u001B[A\n",
      "downloading...:  40%|████      | 30/75 [00:00<00:00, 51.62it/s]\u001B[A\n",
      "downloading...:  53%|█████▎    | 40/75 [00:00<00:00, 44.75it/s]\u001B[A\n",
      "downloading...:  67%|██████▋   | 50/75 [00:01<00:00, 43.17it/s]\u001B[A\n",
      "downloading...:  80%|████████  | 60/75 [00:01<00:00, 39.91it/s]\u001B[A\n",
      "downloading...: 100%|██████████| 75/75 [00:01<00:00, 46.42it/s]\u001B[A\n",
      "  0%|          | 2/1645 [00:04<1:00:45,  2.22s/it]\n",
      "downloading...:   0%|          | 0/90 [00:00<?, ?it/s]\u001B[A\n",
      "downloading...:  22%|██▏       | 20/90 [00:00<00:00, 79.85it/s]\u001B[A\n",
      "downloading...:  33%|███▎      | 30/90 [00:00<00:01, 54.70it/s]\u001B[A\n",
      "downloading...:  44%|████▍     | 40/90 [00:00<00:01, 45.07it/s]\u001B[A\n",
      "downloading...:  56%|█████▌    | 50/90 [00:01<00:00, 43.43it/s]\u001B[A\n",
      "downloading...:  67%|██████▋   | 60/90 [00:01<00:00, 39.82it/s]\u001B[A\n",
      "downloading...:  78%|███████▊  | 70/90 [00:01<00:00, 38.21it/s]\u001B[A\n",
      "downloading...:  89%|████████▉ | 80/90 [00:01<00:00, 36.04it/s]\u001B[A\n",
      "downloading...: 100%|██████████| 90/90 [00:02<00:00, 40.64it/s]\u001B[A\n",
      "  0%|          | 3/1645 [00:07<1:08:53,  2.52s/it]\n",
      "downloading...:   0%|          | 0/92 [00:00<?, ?it/s]\u001B[A\n",
      "downloading...:  22%|██▏       | 20/92 [00:00<00:00, 85.44it/s]\u001B[A\n",
      "downloading...:  33%|███▎      | 30/92 [00:00<00:01, 55.69it/s]\u001B[A\n",
      "downloading...:  43%|████▎     | 40/92 [00:00<00:01, 47.10it/s]\u001B[A\n",
      "downloading...:  54%|█████▍    | 50/92 [00:01<00:00, 43.53it/s]\u001B[A\n",
      "downloading...:  65%|██████▌   | 60/92 [00:01<00:00, 38.87it/s]\u001B[A\n",
      "downloading...:  76%|███████▌  | 70/92 [00:01<00:00, 37.75it/s]\u001B[A\n",
      "downloading...:  87%|████████▋ | 80/92 [00:01<00:00, 36.61it/s]\u001B[A\n",
      "downloading...: 100%|██████████| 92/92 [00:02<00:00, 42.16it/s]\u001B[A\n",
      "  0%|          | 4/1645 [00:10<1:12:33,  2.65s/it]\n",
      "downloading...:   0%|          | 0/87 [00:00<?, ?it/s]\u001B[A\n",
      "downloading...:  23%|██▎       | 20/87 [00:00<00:01, 39.59it/s]\u001B[A\n",
      "downloading...:  34%|███▍      | 30/87 [00:00<00:01, 36.26it/s]\u001B[A\n",
      "downloading...:  46%|████▌     | 40/87 [00:01<00:01, 30.18it/s]\u001B[A\n",
      "downloading...:  57%|█████▋    | 50/87 [00:01<00:01, 25.87it/s]\u001B[A\n",
      "downloading...:  69%|██████▉   | 60/87 [00:02<00:00, 27.09it/s]\u001B[A\n",
      "downloading...:  80%|████████  | 70/87 [00:02<00:00, 26.18it/s]\u001B[A\n",
      "downloading...: 100%|██████████| 87/87 [00:03<00:00, 28.97it/s]\u001B[A\n",
      "  0%|          | 5/1645 [00:14<1:28:42,  3.25s/it]\n",
      "downloading...:   0%|          | 0/96 [00:00<?, ?it/s]\u001B[A\n",
      "downloading...:  21%|██        | 20/96 [00:00<00:01, 57.75it/s]\u001B[A\n",
      "downloading...:  31%|███▏      | 30/96 [00:00<00:01, 48.29it/s]\u001B[A\n",
      "downloading...:  42%|████▏     | 40/96 [00:00<00:01, 37.81it/s]\u001B[A\n",
      "downloading...:  52%|█████▏    | 50/96 [00:01<00:01, 37.96it/s]\u001B[A\n",
      "downloading...:  62%|██████▎   | 60/96 [00:01<00:00, 38.72it/s]\u001B[A\n",
      "downloading...:  73%|███████▎  | 70/96 [00:01<00:00, 37.97it/s]\u001B[A\n",
      "downloading...:  83%|████████▎ | 80/96 [00:02<00:00, 36.37it/s]\u001B[A\n",
      "downloading...: 100%|██████████| 96/96 [00:02<00:00, 40.69it/s]\u001B[A\n",
      "  0%|          | 6/1645 [00:17<1:29:59,  3.29s/it]\n",
      "downloading...:   0%|          | 0/84 [00:00<?, ?it/s]\u001B[A\n",
      "downloading...:  24%|██▍       | 20/84 [00:00<00:00, 87.15it/s]\u001B[A\n",
      "downloading...:  36%|███▌      | 30/84 [00:00<00:00, 55.91it/s]\u001B[A\n",
      "downloading...:  48%|████▊     | 40/84 [00:00<00:00, 47.00it/s]\u001B[A\n",
      "downloading...:  60%|█████▉    | 50/84 [00:01<00:00, 41.88it/s]\u001B[A\n",
      "downloading...:  71%|███████▏  | 60/84 [00:01<00:00, 38.69it/s]\u001B[A\n",
      "downloading...:  83%|████████▎ | 70/84 [00:01<00:00, 36.70it/s]\u001B[A\n",
      "downloading...: 100%|██████████| 84/84 [00:01<00:00, 42.65it/s]\u001B[A\n",
      "  0%|          | 7/1645 [00:20<1:25:40,  3.14s/it]\n",
      "downloading...:   0%|          | 0/81 [00:00<?, ?it/s]\u001B[A\n",
      "downloading...:  25%|██▍       | 20/81 [00:00<00:00, 73.38it/s]\u001B[A\n",
      "downloading...:  37%|███▋      | 30/81 [00:00<00:00, 51.61it/s]\u001B[A\n",
      "downloading...:  49%|████▉     | 40/81 [00:00<00:00, 46.54it/s]\u001B[A\n",
      "downloading...:  62%|██████▏   | 50/81 [00:01<00:00, 42.69it/s]\u001B[A\n",
      "downloading...:  74%|███████▍  | 60/81 [00:01<00:00, 41.79it/s]\u001B[A\n",
      "downloading...:  86%|████████▋ | 70/81 [00:01<00:00, 39.26it/s]\u001B[A\n",
      "downloading...: 100%|██████████| 81/81 [00:01<00:00, 43.17it/s]\u001B[A\n",
      "  0%|          | 8/1645 [00:23<1:21:05,  2.97s/it]\n",
      "downloading...:   0%|          | 0/76 [00:00<?, ?it/s]\u001B[A\n",
      "downloading...:  26%|██▋       | 20/76 [00:00<00:00, 67.14it/s]\u001B[A\n",
      "downloading...:  39%|███▉      | 30/76 [00:00<00:00, 50.76it/s]\u001B[A\n",
      "downloading...:  53%|█████▎    | 40/76 [00:00<00:00, 46.33it/s]\u001B[A\n",
      "downloading...:  66%|██████▌   | 50/76 [00:01<00:00, 40.36it/s]\u001B[A\n",
      "downloading...:  79%|███████▉  | 60/76 [00:01<00:00, 38.63it/s]\u001B[A\n",
      "downloading...: 100%|██████████| 76/76 [00:01<00:00, 44.37it/s]\u001B[A\n",
      "  1%|          | 9/1645 [00:25<1:16:49,  2.82s/it]\n",
      "downloading...:   0%|          | 0/74 [00:00<?, ?it/s]\u001B[A\n",
      "downloading...:  27%|██▋       | 20/74 [00:00<00:00, 80.78it/s]\u001B[A\n",
      "downloading...:  41%|████      | 30/74 [00:00<00:01, 39.95it/s]\u001B[A\n",
      "downloading...:  54%|█████▍    | 40/74 [00:00<00:00, 36.57it/s]\u001B[A\n",
      "downloading...:  68%|██████▊   | 50/74 [00:01<00:00, 35.03it/s]\u001B[A\n",
      "downloading...:  81%|████████  | 60/74 [00:01<00:00, 33.68it/s]\u001B[A\n",
      "downloading...: 100%|██████████| 74/74 [00:01<00:00, 38.80it/s]\u001B[A\n",
      "  1%|          | 10/1645 [00:28<1:16:44,  2.82s/it]\n",
      "downloading...:   0%|          | 0/85 [00:00<?, ?it/s]\u001B[A\n",
      "downloading...:  24%|██▎       | 20/85 [00:00<00:00, 68.79it/s]\u001B[A\n",
      "downloading...:  35%|███▌      | 30/85 [00:00<00:01, 52.74it/s]\u001B[A\n",
      "downloading...:  47%|████▋     | 40/85 [00:00<00:01, 43.06it/s]\u001B[A\n",
      "downloading...:  59%|█████▉    | 50/85 [00:01<00:00, 39.40it/s]\u001B[A\n",
      "downloading...:  71%|███████   | 60/85 [00:01<00:00, 36.14it/s]\u001B[A\n",
      "downloading...:  82%|████████▏ | 70/85 [00:02<00:00, 27.46it/s]\u001B[A\n",
      "downloading...: 100%|██████████| 85/85 [00:02<00:00, 35.81it/s]\u001B[A\n",
      "  1%|          | 11/1645 [00:31<1:19:13,  2.91s/it]\n",
      "downloading...:   0%|          | 0/61 [00:00<?, ?it/s]\u001B[A\n",
      "downloading...:  33%|███▎      | 20/61 [00:00<00:00, 69.50it/s]\u001B[A\n",
      "downloading...:  49%|████▉     | 30/61 [00:00<00:00, 51.31it/s]\u001B[A\n",
      "downloading...:  66%|██████▌   | 40/61 [00:00<00:00, 46.47it/s]\u001B[A\n",
      "downloading...:  82%|████████▏ | 50/61 [00:01<00:00, 39.93it/s]\u001B[A\n",
      "downloading...: 100%|██████████| 61/61 [00:01<00:00, 42.08it/s]\u001B[A\n",
      "  1%|          | 12/1645 [00:34<1:15:23,  2.77s/it]\n",
      "downloading...:   0%|          | 0/61 [00:00<?, ?it/s]\u001B[A\n",
      "downloading...:  33%|███▎      | 20/61 [00:00<00:00, 68.19it/s]\u001B[A\n",
      "downloading...:  49%|████▉     | 30/61 [00:00<00:00, 51.26it/s]\u001B[A\n",
      "downloading...:  66%|██████▌   | 40/61 [00:00<00:00, 39.34it/s]\u001B[A\n",
      "downloading...:  82%|████████▏ | 50/61 [00:01<00:00, 24.51it/s]\u001B[A\n",
      "downloading...: 100%|██████████| 61/61 [00:01<00:00, 31.48it/s]\u001B[A\n",
      "  1%|          | 13/1645 [00:36<1:12:24,  2.66s/it]\n",
      "downloading...:   0%|          | 0/85 [00:00<?, ?it/s]\u001B[A\n",
      "downloading...:  24%|██▎       | 20/85 [00:00<00:00, 74.86it/s]\u001B[A\n",
      "downloading...:  35%|███▌      | 30/85 [00:00<00:01, 52.20it/s]\u001B[A\n",
      "downloading...:  47%|████▋     | 40/85 [00:00<00:00, 45.50it/s]\u001B[A\n",
      "downloading...:  59%|█████▉    | 50/85 [00:01<00:00, 39.92it/s]\u001B[A\n",
      "downloading...:  71%|███████   | 60/85 [00:01<00:00, 39.42it/s]\u001B[A\n",
      "downloading...:  82%|████████▏ | 70/85 [00:01<00:00, 38.05it/s]\u001B[A\n",
      "downloading...: 100%|██████████| 85/85 [00:02<00:00, 42.07it/s]\u001B[A\n",
      "  1%|          | 14/1645 [00:39<1:13:13,  2.69s/it]\n",
      "downloading...:   0%|          | 0/74 [00:00<?, ?it/s]\u001B[A\n",
      "downloading...:  27%|██▋       | 20/74 [00:00<00:00, 77.21it/s]\u001B[A\n",
      "downloading...:  41%|████      | 30/74 [00:00<00:00, 55.62it/s]\u001B[A\n",
      "downloading...:  54%|█████▍    | 40/74 [00:00<00:00, 46.63it/s]\u001B[A\n",
      "downloading...:  68%|██████▊   | 50/74 [00:01<00:00, 32.41it/s]\u001B[A\n",
      "downloading...:  81%|████████  | 60/74 [00:01<00:00, 32.33it/s]\u001B[A\n",
      "downloading...: 100%|██████████| 74/74 [00:01<00:00, 39.21it/s]\u001B[A\n",
      "  1%|          | 15/1645 [00:41<1:12:25,  2.67s/it]\n",
      "downloading...:   0%|          | 0/73 [00:00<?, ?it/s]\u001B[A\n",
      "downloading...:  27%|██▋       | 20/73 [00:00<00:00, 70.74it/s]\u001B[A\n",
      "downloading...:  41%|████      | 30/73 [00:00<00:00, 51.80it/s]\u001B[A\n",
      "downloading...:  55%|█████▍    | 40/73 [00:00<00:00, 44.68it/s]\u001B[A\n",
      "downloading...:  68%|██████▊   | 50/73 [00:01<00:00, 40.87it/s]\u001B[A\n",
      "downloading...:  82%|████████▏ | 60/73 [00:01<00:00, 39.57it/s]\u001B[A\n",
      "downloading...: 100%|██████████| 73/73 [00:01<00:00, 43.79it/s]\u001B[A\n",
      "  1%|          | 16/1645 [00:44<1:11:24,  2.63s/it]\n",
      "downloading...:   0%|          | 0/71 [00:00<?, ?it/s]\u001B[A\n",
      "downloading...:  28%|██▊       | 20/71 [00:00<00:00, 82.19it/s]\u001B[A\n",
      "downloading...:  42%|████▏     | 30/71 [00:00<00:00, 48.69it/s]\u001B[A\n",
      "downloading...:  56%|█████▋    | 40/71 [00:00<00:00, 39.70it/s]\u001B[A\n",
      "downloading...:  70%|███████   | 50/71 [00:01<00:00, 37.88it/s]\u001B[A\n",
      "downloading...:  85%|████████▍ | 60/71 [00:01<00:00, 37.51it/s]\u001B[A\n",
      "downloading...: 100%|██████████| 71/71 [00:01<00:00, 40.95it/s]\u001B[A\n",
      "  1%|          | 17/1645 [00:46<1:09:31,  2.56s/it]\n",
      "downloading...:   0%|          | 0/33 [00:00<?, ?it/s]\u001B[A\n",
      "downloading...:  61%|██████    | 20/33 [00:00<00:00, 79.96it/s]\u001B[A\n",
      "downloading...: 100%|██████████| 33/33 [00:00<00:00, 66.62it/s]\u001B[A\n",
      "  1%|          | 18/1645 [00:47<57:32,  2.12s/it]  \n",
      "downloading...: 100%|██████████| 17/17 [00:00<00:00, 14181.22it/s]\n",
      "  1%|          | 19/1645 [00:48<45:01,  1.66s/it]\n",
      "downloading...:   0%|          | 0/79 [00:00<?, ?it/s]\u001B[A\n",
      "downloading...:  25%|██▌       | 20/79 [00:00<00:00, 84.46it/s]\u001B[A\n",
      "downloading...:  38%|███▊      | 30/79 [00:00<00:00, 53.76it/s]\u001B[A\n",
      "downloading...:  51%|█████     | 40/79 [00:00<00:00, 43.71it/s]\u001B[A\n",
      "downloading...:  63%|██████▎   | 50/79 [00:01<00:00, 38.18it/s]\u001B[A\n",
      "downloading...:  76%|███████▌  | 60/79 [00:01<00:00, 36.35it/s]\u001B[A\n",
      "downloading...: 100%|██████████| 79/79 [00:01<00:00, 43.45it/s]\u001B[A\n",
      "  1%|          | 20/1645 [00:51<55:06,  2.03s/it]\n",
      "downloading...:   0%|          | 0/68 [00:00<?, ?it/s]\u001B[A\n",
      "downloading...:  29%|██▉       | 20/68 [00:00<00:00, 75.12it/s]\u001B[A\n",
      "downloading...:  44%|████▍     | 30/68 [00:00<00:00, 48.20it/s]\u001B[A\n",
      "downloading...:  59%|█████▉    | 40/68 [00:00<00:00, 42.20it/s]\u001B[A\n",
      "downloading...:  74%|███████▎  | 50/68 [00:01<00:00, 39.00it/s]\u001B[A\n",
      "downloading...: 100%|██████████| 68/68 [00:01<00:00, 46.29it/s]\u001B[A\n",
      "  1%|▏         | 21/1645 [00:53<57:28,  2.12s/it]\n",
      "downloading...:   0%|          | 0/82 [00:00<?, ?it/s]\u001B[A\n",
      "downloading...:  24%|██▍       | 20/82 [00:00<00:00, 68.59it/s]\u001B[A\n",
      "downloading...:  37%|███▋      | 30/82 [00:00<00:01, 49.30it/s]\u001B[A\n",
      "downloading...:  49%|████▉     | 40/82 [00:00<00:00, 45.71it/s]\u001B[A\n",
      "downloading...:  61%|██████    | 50/82 [00:01<00:00, 41.58it/s]\u001B[A\n",
      "downloading...:  73%|███████▎  | 60/82 [00:01<00:00, 40.23it/s]\u001B[A\n",
      "downloading...:  85%|████████▌ | 70/82 [00:02<00:00, 26.56it/s]\u001B[A\n",
      "downloading...: 100%|██████████| 82/82 [00:02<00:00, 35.24it/s]\u001B[A\n",
      "  1%|▏         | 22/1645 [00:56<1:04:43,  2.39s/it]\n",
      "downloading...:   0%|          | 0/74 [00:00<?, ?it/s]\u001B[A\n",
      "downloading...:  27%|██▋       | 20/74 [00:00<00:00, 74.92it/s]\u001B[A\n",
      "downloading...:  41%|████      | 30/74 [00:00<00:00, 53.88it/s]\u001B[A\n",
      "downloading...:  54%|█████▍    | 40/74 [00:00<00:00, 47.24it/s]\u001B[A\n",
      "downloading...:  68%|██████▊   | 50/74 [00:01<00:00, 41.56it/s]\u001B[A\n",
      "downloading...:  81%|████████  | 60/74 [00:01<00:00, 38.08it/s]\u001B[A\n",
      "downloading...: 100%|██████████| 74/74 [00:01<00:00, 43.91it/s]\u001B[A\n",
      "  1%|▏         | 23/1645 [00:59<1:05:16,  2.41s/it]\n",
      "downloading...:   0%|          | 0/76 [00:00<?, ?it/s]\u001B[A\n",
      "downloading...:  26%|██▋       | 20/76 [00:00<00:00, 74.71it/s]\u001B[A\n",
      "downloading...:  39%|███▉      | 30/76 [00:00<00:00, 55.47it/s]\u001B[A\n",
      "downloading...:  53%|█████▎    | 40/76 [00:00<00:00, 42.20it/s]\u001B[A\n",
      "downloading...:  66%|██████▌   | 50/76 [00:01<00:00, 33.56it/s]\u001B[A\n",
      "downloading...:  79%|███████▉  | 60/76 [00:01<00:00, 33.92it/s]\u001B[A\n",
      "downloading...: 100%|██████████| 76/76 [00:01<00:00, 41.19it/s]\u001B[A\n",
      "  1%|▏         | 24/1645 [01:01<1:06:58,  2.48s/it]\n",
      "downloading...:   0%|          | 0/74 [00:00<?, ?it/s]\u001B[A\n",
      "downloading...:  27%|██▋       | 20/74 [00:00<00:00, 61.96it/s]\u001B[A\n",
      "downloading...:  41%|████      | 30/74 [00:00<00:00, 45.07it/s]\u001B[A\n",
      "downloading...:  54%|█████▍    | 40/74 [00:00<00:00, 38.07it/s]\u001B[A\n",
      "downloading...:  68%|██████▊   | 50/74 [00:01<00:00, 36.47it/s]\u001B[A\n",
      "downloading...:  81%|████████  | 60/74 [00:01<00:00, 35.17it/s]\u001B[A\n",
      "downloading...: 100%|██████████| 74/74 [00:01<00:00, 40.14it/s]\u001B[A\n",
      "  2%|▏         | 25/1645 [01:04<1:07:55,  2.52s/it]\n",
      "downloading...: 100%|██████████| 3/3 [00:00<00:00, 3864.53it/s]\n",
      "  2%|▏         | 26/1645 [01:04<49:30,  1.84s/it]  \n",
      "downloading...:   0%|          | 0/84 [00:00<?, ?it/s]\u001B[A\n",
      "downloading...:  24%|██▍       | 20/84 [00:00<00:00, 79.35it/s]\u001B[A\n",
      "downloading...:  36%|███▌      | 30/84 [00:00<00:01, 46.72it/s]\u001B[A\n",
      "downloading...:  48%|████▊     | 40/84 [00:00<00:00, 44.12it/s]\u001B[A\n",
      "downloading...:  60%|█████▉    | 50/84 [00:01<00:00, 42.45it/s]\u001B[A\n",
      "downloading...:  71%|███████▏  | 60/84 [00:01<00:00, 39.25it/s]\u001B[A\n",
      "downloading...:  83%|████████▎ | 70/84 [00:01<00:00, 38.02it/s]\u001B[A\n",
      "downloading...: 100%|██████████| 84/84 [00:01<00:00, 42.58it/s]\u001B[A\n",
      "  2%|▏         | 27/1645 [01:07<56:36,  2.10s/it]\n",
      "downloading...:   0%|          | 0/72 [00:00<?, ?it/s]\u001B[A\n",
      "downloading...:  28%|██▊       | 20/72 [00:00<00:00, 87.32it/s]\u001B[A\n",
      "downloading...:  42%|████▏     | 30/72 [00:00<00:00, 55.84it/s]\u001B[A\n",
      "downloading...:  56%|█████▌    | 40/72 [00:00<00:00, 46.76it/s]\u001B[A\n",
      "downloading...:  69%|██████▉   | 50/72 [00:01<00:00, 42.00it/s]\u001B[A\n",
      "downloading...:  83%|████████▎ | 60/72 [00:01<00:00, 39.78it/s]\u001B[A\n",
      "downloading...: 100%|██████████| 72/72 [00:01<00:00, 44.43it/s]\u001B[A\n",
      "  2%|▏         | 28/1645 [01:09<58:33,  2.17s/it]\n",
      "downloading...:   0%|          | 0/79 [00:00<?, ?it/s]\u001B[A\n",
      "downloading...:  25%|██▌       | 20/79 [00:00<00:00, 66.44it/s]\u001B[A\n",
      "downloading...:  38%|███▊      | 30/79 [00:00<00:01, 43.92it/s]\u001B[A\n",
      "downloading...:  51%|█████     | 40/79 [00:00<00:00, 39.35it/s]\u001B[A\n",
      "downloading...:  63%|██████▎   | 50/79 [00:01<00:00, 37.63it/s]\u001B[A\n",
      "downloading...:  76%|███████▌  | 60/79 [00:01<00:00, 36.48it/s]\u001B[A\n",
      "downloading...: 100%|██████████| 79/79 [00:01<00:00, 43.21it/s]\u001B[A\n",
      "  2%|▏         | 29/1645 [01:12<1:03:29,  2.36s/it]\n",
      "downloading...:   0%|          | 0/84 [00:00<?, ?it/s]\u001B[A\n",
      "downloading...:  24%|██▍       | 20/84 [00:00<00:00, 82.74it/s]\u001B[A\n",
      "downloading...:  36%|███▌      | 30/84 [00:00<00:00, 56.25it/s]\u001B[A\n",
      "downloading...:  48%|████▊     | 40/84 [00:00<00:00, 50.10it/s]\u001B[A\n",
      "downloading...:  60%|█████▉    | 50/84 [00:01<00:00, 44.90it/s]\u001B[A\n",
      "downloading...:  71%|███████▏  | 60/84 [00:01<00:00, 43.01it/s]\u001B[A\n",
      "downloading...:  83%|████████▎ | 70/84 [00:01<00:00, 39.04it/s]\u001B[A\n",
      "downloading...: 100%|██████████| 84/84 [00:01<00:00, 44.73it/s]\u001B[A\n",
      "  2%|▏         | 30/1645 [01:15<1:05:27,  2.43s/it]\n",
      "downloading...:   0%|          | 0/85 [00:00<?, ?it/s]\u001B[A\n",
      "downloading...:  24%|██▎       | 20/85 [00:00<00:01, 56.47it/s]\u001B[A\n",
      "downloading...:  35%|███▌      | 30/85 [00:00<00:01, 49.24it/s]\u001B[A\n",
      "downloading...:  47%|████▋     | 40/85 [00:00<00:01, 44.71it/s]\u001B[A\n",
      "downloading...:  59%|█████▉    | 50/85 [00:01<00:00, 41.35it/s]\u001B[A\n",
      "downloading...:  71%|███████   | 60/85 [00:01<00:00, 39.31it/s]\u001B[A\n",
      "downloading...:  82%|████████▏ | 70/85 [00:01<00:00, 37.04it/s]\u001B[A\n",
      "downloading...: 100%|██████████| 85/85 [00:02<00:00, 42.03it/s]\u001B[A\n",
      "  2%|▏         | 31/1645 [01:17<1:07:56,  2.53s/it]\n",
      "downloading...:   0%|          | 0/76 [00:00<?, ?it/s]\u001B[A\n",
      "downloading...:  26%|██▋       | 20/76 [00:00<00:00, 74.62it/s]\u001B[A\n",
      "downloading...:  39%|███▉      | 30/76 [00:00<00:00, 54.56it/s]\u001B[A\n",
      "downloading...:  53%|█████▎    | 40/76 [00:00<00:00, 46.68it/s]\u001B[A\n",
      "downloading...:  66%|██████▌   | 50/76 [00:01<00:00, 43.02it/s]\u001B[A\n",
      "downloading...:  79%|███████▉  | 60/76 [00:01<00:00, 40.30it/s]\u001B[A\n",
      "downloading...: 100%|██████████| 76/76 [00:01<00:00, 46.18it/s]\u001B[A\n",
      "  2%|▏         | 32/1645 [01:20<1:07:39,  2.52s/it]\n",
      "downloading...:   0%|          | 0/62 [00:00<?, ?it/s]\u001B[A\n",
      "downloading...:  65%|██████▍   | 40/62 [00:00<00:00, 187.80it/s]\u001B[A\n",
      "downloading...: 100%|██████████| 62/62 [00:00<00:00, 146.47it/s]\u001B[A\n",
      "  2%|▏         | 33/1645 [01:21<53:51,  2.00s/it]  \n",
      "downloading...:   0%|          | 0/77 [00:00<?, ?it/s]\u001B[A\n",
      "downloading...:  26%|██▌       | 20/77 [00:00<00:00, 73.71it/s]\u001B[A\n",
      "downloading...:  39%|███▉      | 30/77 [00:00<00:00, 53.22it/s]\u001B[A\n",
      "downloading...:  52%|█████▏    | 40/77 [00:00<00:00, 45.49it/s]\u001B[A\n",
      "downloading...:  65%|██████▍   | 50/77 [00:01<00:00, 42.35it/s]\u001B[A\n",
      "downloading...:  78%|███████▊  | 60/77 [00:01<00:00, 40.59it/s]\u001B[A\n",
      "downloading...: 100%|██████████| 77/77 [00:01<00:00, 46.59it/s]\u001B[A\n",
      "  2%|▏         | 34/1645 [01:23<57:15,  2.13s/it]\n",
      "downloading...:   0%|          | 0/99 [00:00<?, ?it/s]\u001B[A\n",
      "downloading...:  20%|██        | 20/99 [00:00<00:01, 67.70it/s]\u001B[A\n",
      "downloading...:  30%|███       | 30/99 [00:00<00:01, 47.03it/s]\u001B[A\n",
      "downloading...:  40%|████      | 40/99 [00:00<00:01, 43.72it/s]\u001B[A\n",
      "downloading...:  51%|█████     | 50/99 [00:01<00:01, 40.49it/s]\u001B[A\n",
      "downloading...:  61%|██████    | 60/99 [00:01<00:01, 38.60it/s]\u001B[A\n",
      "downloading...:  71%|███████   | 70/99 [00:01<00:00, 32.98it/s]\u001B[A\n",
      "downloading...:  81%|████████  | 80/99 [00:02<00:00, 31.74it/s]\u001B[A\n",
      "downloading...: 100%|██████████| 99/99 [00:02<00:00, 39.56it/s]\u001B[A\n",
      "  2%|▏         | 35/1645 [01:27<1:09:06,  2.58s/it]\n",
      "downloading...:   0%|          | 0/99 [00:00<?, ?it/s]\u001B[A\n",
      "downloading...:  20%|██        | 20/99 [00:00<00:01, 76.87it/s]\u001B[A\n",
      "downloading...:  30%|███       | 30/99 [00:00<00:01, 52.04it/s]\u001B[A\n",
      "downloading...:  40%|████      | 40/99 [00:00<00:01, 46.27it/s]\u001B[A\n",
      "downloading...:  51%|█████     | 50/99 [00:01<00:01, 39.75it/s]\u001B[A\n",
      "downloading...:  61%|██████    | 60/99 [00:01<00:01, 38.78it/s]\u001B[A\n",
      "downloading...:  71%|███████   | 70/99 [00:01<00:00, 38.99it/s]\u001B[A\n",
      "downloading...:  81%|████████  | 80/99 [00:01<00:00, 38.49it/s]\u001B[A\n",
      "downloading...: 100%|██████████| 99/99 [00:02<00:00, 44.21it/s]\u001B[A\n",
      "  2%|▏         | 36/1645 [01:30<1:15:16,  2.81s/it]\n",
      "downloading...:   0%|          | 0/99 [00:00<?, ?it/s]\u001B[A\n",
      "downloading...:  20%|██        | 20/99 [00:00<00:00, 81.51it/s]\u001B[A\n",
      "downloading...:  30%|███       | 30/99 [00:00<00:01, 55.57it/s]\u001B[A\n",
      "downloading...:  40%|████      | 40/99 [00:00<00:01, 46.59it/s]\u001B[A\n",
      "downloading...:  51%|█████     | 50/99 [00:01<00:01, 42.76it/s]\u001B[A\n",
      "downloading...:  61%|██████    | 60/99 [00:01<00:00, 39.99it/s]\u001B[A\n",
      "downloading...:  71%|███████   | 70/99 [00:01<00:00, 36.97it/s]\u001B[A\n",
      "downloading...:  81%|████████  | 80/99 [00:01<00:00, 36.19it/s]\u001B[A\n",
      "downloading...: 100%|██████████| 99/99 [00:02<00:00, 44.73it/s]\u001B[A\n",
      "  2%|▏         | 37/1645 [01:33<1:17:07,  2.88s/it]\n",
      "downloading...:   0%|          | 0/99 [00:00<?, ?it/s]\u001B[A\n",
      "downloading...:  20%|██        | 20/99 [00:00<00:01, 70.32it/s]\u001B[A\n",
      "downloading...:  30%|███       | 30/99 [00:00<00:01, 53.04it/s]\u001B[A\n",
      "downloading...:  40%|████      | 40/99 [00:00<00:01, 42.62it/s]\u001B[A\n",
      "downloading...:  51%|█████     | 50/99 [00:01<00:01, 39.95it/s]\u001B[A\n",
      "downloading...:  61%|██████    | 60/99 [00:01<00:00, 39.43it/s]\u001B[A\n",
      "downloading...:  71%|███████   | 70/99 [00:01<00:00, 35.88it/s]\u001B[A\n",
      "downloading...:  81%|████████  | 80/99 [00:02<00:00, 35.18it/s]\u001B[A\n",
      "downloading...: 100%|██████████| 99/99 [00:02<00:00, 39.41it/s]\u001B[A\n",
      "  2%|▏         | 38/1645 [01:37<1:22:09,  3.07s/it]\n",
      "downloading...:   0%|          | 0/99 [00:00<?, ?it/s]\u001B[A\n",
      "downloading...:  20%|██        | 20/99 [00:00<00:01, 72.40it/s]\u001B[A\n",
      "downloading...:  30%|███       | 30/99 [00:00<00:01, 49.10it/s]\u001B[A\n",
      "downloading...:  40%|████      | 40/99 [00:00<00:01, 42.43it/s]\u001B[A\n",
      "downloading...:  51%|█████     | 50/99 [00:01<00:01, 41.49it/s]\u001B[A\n",
      "downloading...:  61%|██████    | 60/99 [00:01<00:00, 39.06it/s]\u001B[A\n",
      "downloading...:  71%|███████   | 70/99 [00:01<00:00, 36.99it/s]\u001B[A\n",
      "downloading...:  81%|████████  | 80/99 [00:01<00:00, 37.51it/s]\u001B[A\n",
      "downloading...: 100%|██████████| 99/99 [00:02<00:00, 44.06it/s]\u001B[A\n",
      "  2%|▏         | 39/1645 [01:40<1:23:26,  3.12s/it]\n",
      "downloading...:   0%|          | 0/99 [00:00<?, ?it/s]\u001B[A\n",
      "downloading...:  20%|██        | 20/99 [00:00<00:01, 66.41it/s]\u001B[A\n",
      "downloading...:  30%|███       | 30/99 [00:00<00:01, 48.81it/s]\u001B[A\n",
      "downloading...:  40%|████      | 40/99 [00:00<00:01, 43.04it/s]\u001B[A\n",
      "downloading...:  51%|█████     | 50/99 [00:01<00:01, 40.29it/s]\u001B[A\n",
      "downloading...:  61%|██████    | 60/99 [00:01<00:00, 39.69it/s]\u001B[A\n",
      "downloading...:  71%|███████   | 70/99 [00:01<00:00, 37.96it/s]\u001B[A\n",
      "downloading...:  81%|████████  | 80/99 [00:01<00:00, 36.55it/s]\u001B[A\n",
      "downloading...: 100%|██████████| 99/99 [00:02<00:00, 43.82it/s]\u001B[A\n",
      "  2%|▏         | 40/1645 [01:43<1:23:41,  3.13s/it]\n",
      "downloading...:   0%|          | 0/99 [00:00<?, ?it/s]\u001B[A\n",
      "downloading...:  20%|██        | 20/99 [00:00<00:00, 79.10it/s]\u001B[A\n",
      "downloading...:  30%|███       | 30/99 [00:00<00:01, 53.82it/s]\u001B[A\n",
      "downloading...:  40%|████      | 40/99 [00:00<00:01, 46.85it/s]\u001B[A\n",
      "downloading...:  51%|█████     | 50/99 [00:01<00:01, 41.13it/s]\u001B[A\n",
      "downloading...:  61%|██████    | 60/99 [00:01<00:00, 40.04it/s]\u001B[A\n",
      "downloading...:  71%|███████   | 70/99 [00:01<00:00, 38.72it/s]\u001B[A\n",
      "downloading...:  81%|████████  | 80/99 [00:01<00:00, 37.44it/s]\u001B[A\n",
      "downloading...: 100%|██████████| 99/99 [00:02<00:00, 41.17it/s]\u001B[A\n",
      "  2%|▏         | 41/1645 [01:47<1:26:58,  3.25s/it]\n",
      "downloading...:   0%|          | 0/99 [00:00<?, ?it/s]\u001B[A\n",
      "downloading...:  20%|██        | 20/99 [00:00<00:01, 78.73it/s]\u001B[A\n",
      "downloading...:  30%|███       | 30/99 [00:00<00:01, 54.01it/s]\u001B[A\n",
      "downloading...:  40%|████      | 40/99 [00:00<00:01, 46.63it/s]\u001B[A\n",
      "downloading...:  51%|█████     | 50/99 [00:01<00:01, 44.32it/s]\u001B[A\n",
      "downloading...:  61%|██████    | 60/99 [00:01<00:00, 41.28it/s]\u001B[A\n",
      "downloading...:  71%|███████   | 70/99 [00:01<00:00, 40.86it/s]\u001B[A\n",
      "downloading...:  81%|████████  | 80/99 [00:01<00:00, 39.41it/s]\u001B[A\n",
      "downloading...: 100%|██████████| 99/99 [00:02<00:00, 46.29it/s]\u001B[A\n",
      "  3%|▎         | 42/1645 [01:50<1:28:05,  3.30s/it]\n",
      "downloading...:   0%|          | 0/99 [00:00<?, ?it/s]\u001B[A\n",
      "downloading...:  20%|██        | 20/99 [00:00<00:00, 84.92it/s]\u001B[A\n",
      "downloading...:  30%|███       | 30/99 [00:00<00:01, 54.49it/s]\u001B[A\n",
      "downloading...:  40%|████      | 40/99 [00:00<00:01, 40.07it/s]\u001B[A\n",
      "downloading...:  51%|█████     | 50/99 [00:01<00:01, 38.35it/s]\u001B[A\n",
      "downloading...:  61%|██████    | 60/99 [00:01<00:01, 37.30it/s]\u001B[A\n",
      "downloading...:  71%|███████   | 70/99 [00:01<00:00, 36.62it/s]\u001B[A\n",
      "downloading...:  81%|████████  | 80/99 [00:02<00:00, 35.42it/s]\u001B[A\n",
      "downloading...: 100%|██████████| 99/99 [00:02<00:00, 42.52it/s]\u001B[A\n",
      "  3%|▎         | 43/1645 [01:53<1:28:56,  3.33s/it]\n",
      "downloading...:   0%|          | 0/99 [00:00<?, ?it/s]\u001B[A\n",
      "downloading...:  20%|██        | 20/99 [00:00<00:00, 79.65it/s]\u001B[A\n",
      "downloading...:  30%|███       | 30/99 [00:00<00:01, 53.04it/s]\u001B[A\n",
      "downloading...:  40%|████      | 40/99 [00:00<00:01, 46.90it/s]\u001B[A\n",
      "downloading...:  51%|█████     | 50/99 [00:01<00:01, 41.26it/s]\u001B[A\n",
      "downloading...:  61%|██████    | 60/99 [00:01<00:01, 33.57it/s]\u001B[A\n",
      "downloading...:  71%|███████   | 70/99 [00:01<00:00, 34.25it/s]\u001B[A\n",
      "downloading...:  81%|████████  | 80/99 [00:02<00:00, 34.07it/s]\u001B[A\n",
      "downloading...: 100%|██████████| 99/99 [00:02<00:00, 41.48it/s]\u001B[A\n",
      "  3%|▎         | 43/1645 [01:56<1:12:27,  2.71s/it]\n"
     ]
    },
    {
     "ename": "KeyboardInterrupt",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001B[0;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[0;31mKeyboardInterrupt\u001B[0m                         Traceback (most recent call last)",
      "\u001B[0;32m<ipython-input-44-10774f1c6303>\u001B[0m in \u001B[0;36m<module>\u001B[0;34m\u001B[0m\n\u001B[1;32m      4\u001B[0m                            \u001B[0mstart_date\u001B[0m\u001B[0;34m=\u001B[0m\u001B[0mtemp_data\u001B[0m\u001B[0;34m[\u001B[0m\u001B[0;34m'上市日期'\u001B[0m\u001B[0;34m]\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mstrip\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m,\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m      5\u001B[0m                            end_date='2021-10-25')\n\u001B[0;32m----> 6\u001B[0;31m     \u001B[0mtemp_result\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mtemp_dlstock\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mrun\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m      7\u001B[0m     \u001B[0mtemp_result\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mto_csv\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34mf\"{dir_name}/{temp_data['公司简称'].strip()}_{temp_data['公司代码']}.csv\"\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mindex\u001B[0m\u001B[0;34m=\u001B[0m\u001B[0;32mFalse\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m      8\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0;32m~/PycharmProjects/time_series/股票数据/downloaddata.py\u001B[0m in \u001B[0;36mrun\u001B[0;34m(self)\u001B[0m\n\u001B[1;32m     68\u001B[0m     \u001B[0;32mdef\u001B[0m \u001B[0mrun\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mself\u001B[0m\u001B[0;34m)\u001B[0m \u001B[0;34m->\u001B[0m \u001B[0mpd\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mDataFrame\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m     69\u001B[0m         \u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mgenerat_index_data\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m---> 70\u001B[0;31m         result_list = Parallel(n_jobs=self.njobs)(\n\u001B[0m\u001B[1;32m     71\u001B[0m             delayed(self.dl_data_by_index)(index) for index in tqdm(range(self.index_range_max), desc=\"downloading...\"))\n\u001B[1;32m     72\u001B[0m         \u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mfinaldata\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mpd\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mconcat\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mresult_list\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0msort_values\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mby\u001B[0m\u001B[0;34m=\u001B[0m\u001B[0;34m[\u001B[0m\u001B[0;34m'日期'\u001B[0m\u001B[0;34m]\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mreset_index\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mdrop\u001B[0m\u001B[0;34m=\u001B[0m\u001B[0;32mTrue\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0;32m/opt/anaconda3/envs/devc/lib/python3.8/site-packages/joblib/parallel.py\u001B[0m in \u001B[0;36m__call__\u001B[0;34m(self, iterable)\u001B[0m\n\u001B[1;32m   1052\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m   1053\u001B[0m             \u001B[0;32mwith\u001B[0m \u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0m_backend\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mretrieval_context\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m-> 1054\u001B[0;31m                 \u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mretrieve\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m   1055\u001B[0m             \u001B[0;31m# Make sure that we get a last message telling us we are done\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m   1056\u001B[0m             \u001B[0melapsed_time\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mtime\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mtime\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m)\u001B[0m \u001B[0;34m-\u001B[0m \u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0m_start_time\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0;32m/opt/anaconda3/envs/devc/lib/python3.8/site-packages/joblib/parallel.py\u001B[0m in \u001B[0;36mretrieve\u001B[0;34m(self)\u001B[0m\n\u001B[1;32m    931\u001B[0m             \u001B[0;32mtry\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m    932\u001B[0m                 \u001B[0;32mif\u001B[0m \u001B[0mgetattr\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0m_backend\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0;34m'supports_timeout'\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0;32mFalse\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m--> 933\u001B[0;31m                     \u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0m_output\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mextend\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mjob\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mget\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mtimeout\u001B[0m\u001B[0;34m=\u001B[0m\u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mtimeout\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m    934\u001B[0m                 \u001B[0;32melse\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m    935\u001B[0m                     \u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0m_output\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mextend\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mjob\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mget\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0;32m/opt/anaconda3/envs/devc/lib/python3.8/site-packages/joblib/_parallel_backends.py\u001B[0m in \u001B[0;36mwrap_future_result\u001B[0;34m(future, timeout)\u001B[0m\n\u001B[1;32m    540\u001B[0m         AsyncResults.get from multiprocessing.\"\"\"\n\u001B[1;32m    541\u001B[0m         \u001B[0;32mtry\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m--> 542\u001B[0;31m             \u001B[0;32mreturn\u001B[0m \u001B[0mfuture\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mresult\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mtimeout\u001B[0m\u001B[0;34m=\u001B[0m\u001B[0mtimeout\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m    543\u001B[0m         \u001B[0;32mexcept\u001B[0m \u001B[0mCfTimeoutError\u001B[0m \u001B[0;32mas\u001B[0m \u001B[0me\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m    544\u001B[0m             \u001B[0;32mraise\u001B[0m \u001B[0mTimeoutError\u001B[0m \u001B[0;32mfrom\u001B[0m \u001B[0me\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0;32m/opt/anaconda3/envs/devc/lib/python3.8/concurrent/futures/_base.py\u001B[0m in \u001B[0;36mresult\u001B[0;34m(self, timeout)\u001B[0m\n\u001B[1;32m    432\u001B[0m                 \u001B[0;32mreturn\u001B[0m \u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0m__get_result\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m    433\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m--> 434\u001B[0;31m             \u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0m_condition\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mwait\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mtimeout\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m    435\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m    436\u001B[0m             \u001B[0;32mif\u001B[0m \u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0m_state\u001B[0m \u001B[0;32min\u001B[0m \u001B[0;34m[\u001B[0m\u001B[0mCANCELLED\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mCANCELLED_AND_NOTIFIED\u001B[0m\u001B[0;34m]\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0;32m/opt/anaconda3/envs/devc/lib/python3.8/threading.py\u001B[0m in \u001B[0;36mwait\u001B[0;34m(self, timeout)\u001B[0m\n\u001B[1;32m    300\u001B[0m         \u001B[0;32mtry\u001B[0m\u001B[0;34m:\u001B[0m    \u001B[0;31m# restore state no matter what (e.g., KeyboardInterrupt)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m    301\u001B[0m             \u001B[0;32mif\u001B[0m \u001B[0mtimeout\u001B[0m \u001B[0;32mis\u001B[0m \u001B[0;32mNone\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m--> 302\u001B[0;31m                 \u001B[0mwaiter\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0macquire\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m    303\u001B[0m                 \u001B[0mgotit\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0;32mTrue\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m    304\u001B[0m             \u001B[0;32melse\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0;31mKeyboardInterrupt\u001B[0m: "
     ]
    }
   ],
   "source": [
    "for index in tqdm(range(0, 10)):  #tqdm(range(0, sz_A_stock_data.shape[0])):\n",
    "    temp_data = sz_A_stock_data.iloc[index]\n",
    "    temp_dlstock = DlStock(stock_id=temp_data['公司代码'],\n",
    "                           start_date=temp_data['上市日期'].strip(),\n",
    "                           end_date='2021-10-25')\n",
    "    temp_result = temp_dlstock.run()\n",
    "    temp_result.to_csv(f\"{dir_name}/{temp_data['公司简称'].strip()}_{temp_data['公司代码']}.csv\", index=False)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "## 方法2.使用并行下载数据\n",
    "\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████| 1645/1645 [31:35<00:00,  1.15s/it] \n"
     ]
    },
    {
     "ename": "TerminatedWorkerError",
     "evalue": "A worker process managed by the executor was unexpectedly terminated. This could be caused by a segmentation fault while calling the function or by an excessive memory usage causing the Operating System to kill the worker.\n\nThe exit codes of the workers are {SIGKILL(-9)}",
     "output_type": "error",
     "traceback": [
      "\u001B[0;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[0;31mTerminatedWorkerError\u001B[0m                     Traceback (most recent call last)",
      "\u001B[0;32m<ipython-input-6-bbfef6694d97>\u001B[0m in \u001B[0;36m<module>\u001B[0;34m\u001B[0m\n\u001B[1;32m     31\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m     32\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m---> 33\u001B[0;31m check_index_list = Parallel(n_jobs=10)(delayed(dl_by_parallel)(index)\n\u001B[0m\u001B[1;32m     34\u001B[0m                                        for index in tqdm(range(0, sz_A_stock_data.shape[0])))\n\u001B[1;32m     35\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0;32m/opt/anaconda3/envs/devc/lib/python3.8/site-packages/joblib/parallel.py\u001B[0m in \u001B[0;36m__call__\u001B[0;34m(self, iterable)\u001B[0m\n\u001B[1;32m   1052\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m   1053\u001B[0m             \u001B[0;32mwith\u001B[0m \u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0m_backend\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mretrieval_context\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m-> 1054\u001B[0;31m                 \u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mretrieve\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m   1055\u001B[0m             \u001B[0;31m# Make sure that we get a last message telling us we are done\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m   1056\u001B[0m             \u001B[0melapsed_time\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mtime\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mtime\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m)\u001B[0m \u001B[0;34m-\u001B[0m \u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0m_start_time\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0;32m/opt/anaconda3/envs/devc/lib/python3.8/site-packages/joblib/parallel.py\u001B[0m in \u001B[0;36mretrieve\u001B[0;34m(self)\u001B[0m\n\u001B[1;32m    931\u001B[0m             \u001B[0;32mtry\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m    932\u001B[0m                 \u001B[0;32mif\u001B[0m \u001B[0mgetattr\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0m_backend\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0;34m'supports_timeout'\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0;32mFalse\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m--> 933\u001B[0;31m                     \u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0m_output\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mextend\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mjob\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mget\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mtimeout\u001B[0m\u001B[0;34m=\u001B[0m\u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mtimeout\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m    934\u001B[0m                 \u001B[0;32melse\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m    935\u001B[0m                     \u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0m_output\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mextend\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mjob\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mget\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0;32m/opt/anaconda3/envs/devc/lib/python3.8/site-packages/joblib/_parallel_backends.py\u001B[0m in \u001B[0;36mwrap_future_result\u001B[0;34m(future, timeout)\u001B[0m\n\u001B[1;32m    540\u001B[0m         AsyncResults.get from multiprocessing.\"\"\"\n\u001B[1;32m    541\u001B[0m         \u001B[0;32mtry\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m--> 542\u001B[0;31m             \u001B[0;32mreturn\u001B[0m \u001B[0mfuture\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mresult\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mtimeout\u001B[0m\u001B[0;34m=\u001B[0m\u001B[0mtimeout\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m    543\u001B[0m         \u001B[0;32mexcept\u001B[0m \u001B[0mCfTimeoutError\u001B[0m \u001B[0;32mas\u001B[0m \u001B[0me\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m    544\u001B[0m             \u001B[0;32mraise\u001B[0m \u001B[0mTimeoutError\u001B[0m \u001B[0;32mfrom\u001B[0m \u001B[0me\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0;32m/opt/anaconda3/envs/devc/lib/python3.8/concurrent/futures/_base.py\u001B[0m in \u001B[0;36mresult\u001B[0;34m(self, timeout)\u001B[0m\n\u001B[1;32m    437\u001B[0m                 \u001B[0;32mraise\u001B[0m \u001B[0mCancelledError\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m    438\u001B[0m             \u001B[0;32melif\u001B[0m \u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0m_state\u001B[0m \u001B[0;34m==\u001B[0m \u001B[0mFINISHED\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m--> 439\u001B[0;31m                 \u001B[0;32mreturn\u001B[0m \u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0m__get_result\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m    440\u001B[0m             \u001B[0;32melse\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m    441\u001B[0m                 \u001B[0;32mraise\u001B[0m \u001B[0mTimeoutError\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0;32m/opt/anaconda3/envs/devc/lib/python3.8/concurrent/futures/_base.py\u001B[0m in \u001B[0;36m__get_result\u001B[0;34m(self)\u001B[0m\n\u001B[1;32m    386\u001B[0m     \u001B[0;32mdef\u001B[0m \u001B[0m__get_result\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mself\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m    387\u001B[0m         \u001B[0;32mif\u001B[0m \u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0m_exception\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m--> 388\u001B[0;31m             \u001B[0;32mraise\u001B[0m \u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0m_exception\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m    389\u001B[0m         \u001B[0;32melse\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m    390\u001B[0m             \u001B[0;32mreturn\u001B[0m \u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0m_result\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0;31mTerminatedWorkerError\u001B[0m: A worker process managed by the executor was unexpectedly terminated. This could be caused by a segmentation fault while calling the function or by an excessive memory usage causing the Operating System to kill the worker.\n\nThe exit codes of the workers are {SIGKILL(-9)}"
     ]
    }
   ],
   "source": [
    "from joblib import Parallel, delayed\n",
    "\n",
    "dir_name = \"股票下载文件夹\"\n",
    "if os.path.exists(dir_name):\n",
    "    shutil.rmtree(path=dir_name)\n",
    "    os.mkdir(path=dir_name)\n",
    "else:\n",
    "    os.mkdir(path=dir_name)\n",
    "\n",
    "sz_A_stock_data = pd.read_csv(\"上海证券交易所股票名单/主板A股.xls\",\n",
    "                              sep='\\t',\n",
    "                              encoding='gb2312')\n",
    "sz_A_stock_data.columns = [i.strip() for i in sz_A_stock_data.columns.tolist()]\n",
    "sz_A_stock_data.head()\n",
    "\n",
    "\n",
    "def dl_by_parallel(index):\n",
    "    try:\n",
    "        time.sleep(random.randint(0, 10))\n",
    "        temp_data = sz_A_stock_data.iloc[index]\n",
    "        temp_dlstock = DlStock(stock_id=temp_data['公司代码'],\n",
    "                               start_date=temp_data['上市日期'].strip(),\n",
    "                               end_date='2021-10-25')\n",
    "        temp_result = temp_dlstock.run()\n",
    "        temp_result.to_csv(f\"{dir_name}/{temp_data['公司简称'].strip()}_{temp_data['公司代码']}.csv\", index=False)\n",
    "\n",
    "    except Exception as e:\n",
    "        index = 0\n",
    "        pass\n",
    "    finally:\n",
    "        return index\n",
    "\n",
    "\n",
    "check_index_list = Parallel(n_jobs=10)(delayed(dl_by_parallel)(index)\n",
    "                                       for index in tqdm(range(0, sz_A_stock_data.shape[0])))\n",
    "print('done~')"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}